package com.xaicode.algorithm.redis;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Locker cjxia@isoftstone.com
 * @version 1.0
 */
public class LRUCache3 extends LinkedHashMap<Object, Object> {

    private int capacity;

    public LRUCache3(int capacity) {
        super(capacity, 0.75f, true);
        this.capacity = capacity;
    }

    @Override
    public Object get(Object key) {
        return super.getOrDefault(key, null);
    }

    @Override
    public Object put(Object key, Object value) {
        return super.put(key, value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return size() > capacity;
    }
}
